{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Using Memory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook looks at including memory operations in our machine code programs.\n", "\n", "First, some hints from the last homework." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.1 Weird Memory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can use `%dump START STOP` to look at contiguous memory locations." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: xE002\n", " x3001: x6201\n", " x3002: xF025\n", " x3003: xF0F0\n", " x3004: x000F\n", " x3005: x0000\n", " x3006: x0000\n", " x3007: x0000\n", " x3008: x0000\n", " x3009: x0000\n", " x300A: x0000\n" ] } ], "source": [ "%dump x3000 x300A" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you find that you have weird things in memory, you can perform a `%reset` of the LC3:" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Welcome to the LC-3 simulator.\n", "\n", "The contents of the LC-3 tools distribution, including sources, management\n", "tools, and data, are Copyright (c) 2003 Steven S. Lumetta.\n", "\n", "The LC-3 tools distribution is free software covered by the GNU General\n", "Public License, and you are welcome to modify it and/or distribute copies\n", "of it under certain conditions. The file COPYING (distributed with the\n", "tools) specifies those conditions. There is absolutely no warranty for\n", "the LC-3 tools distribution, as described in the file NO_WARRANTY (also\n", "distributed with the tools).\n", "\n", "Have fun.\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3000\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ "%reset" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: x0000\n", " x3001: x0000\n", " x3002: x0000\n", " x3003: x0000\n", " x3004: x0000\n", " x3005: x0000\n", " x3006: x0000\n", " x3007: x0000\n", " x3008: x0000\n", " x3009: x0000\n", " x300A: x0000\n" ] } ], "source": [ "%dump x3000 x300A" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That looks better!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.2 Infinite Loops" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you find yourself running an infinite loop, like this:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: x0FFF\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3001\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3000\n", "0000 111 111111111 ; BRnzp go -1\n", ".END" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Keyboard Interrupt!\n" ] } ], "source": [ "%exe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Press the black square in the toolbar, or select menu -> Kernel -> Interrupt. That should send a `Keyboard Interrupt` to the LC3 and stop it from running." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.3 Clear" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There is no CLR instruction. You can use something like:\n", "\n", "```gas\n", "0101 001 001 1 00000 ;; AND R0, R0, #0\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.4 Using BR" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Using a BR instruction is the only way to have any program control at all. There is no IF, FOR, WHILE, etc. You have to use BR to build such constructs." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: x1020\n", " x3001: x102A\n", " x3002: x0403\n", " x3003: x1220\n", " x3004: x103F\n", " x3005: x0FFC\n", " x3006: xF025\n", " x3007: x0000\n", " x3008: x0000\n", " x3009: x0000\n", " x300A: x0000\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3007\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3000\n", "0101 000 000 1 00000 ; R0 to 0\n", "0001 000 000 1 01010 ; R0 <- R0 \n", "0000 010 000000011 ; BRp go to +3\n", "0001 001 000 0 00 000 ; R1 <- R0 \n", "0001 000 000 1 11111 ; R0 - 1\n", "0000 111 111111100 ; BR go to -4\n", "1111 0000 00100101 ; HALT\n", ".END" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 44\n", "Cycles: 267 (0.000133 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0001 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x3007 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.5 Don't use a calculator, use your programming languages!" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0b11111111\n", "0xff\n" ] } ], "source": [ "%%python\n", "\n", "print(bin(16 * 15 + 15))\n", "print(hex(16 * 15 + 15))\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.6 Loading Memory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can stick data into memory using the .ORIG directive:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3001: xFFFF\n", " x3002: x0000\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3002\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3001\n", "1111111111111111\n", ".END" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: xFFFE\n", " x3001: xFFFF\n", " x3002: x0000\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3001\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3000\n", "1111111111111110\n", ".END" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false, "format": "tab" }, "outputs": [ { "data": { "text/html": [ "\n", "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.7 Loading from Memory" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.7.1 LD - Load" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```gas\n", "LD R4, VALUE ; R4 <- mem[VALUE]\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "15 - 12 | 11 - 9 | 8 - 0 |\n", "----| ------ | ----\n", "0010 | DR | PCoffset9\n", "\n", "
\n", "\n", "* DR <- mem[ PC+ + SEXT(PCoffset9) ]\n", "* sets condition codes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.7.2 LDI - Load Indirect" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```gas\n", "LDI R4, VALUE ; R4 <- mem[mem[VALUE]]\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "15 - 12 | 11 - 9 | 8 - 0 |\n", "----| ------ | ----\n", "1010 | DR | PCoffset9\n", "\n", "
\n", "\n", "* DR <- mem[mem[ PC+ + SEXT(PCoffset9) ]]\n", "* sets condition codes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.7.3 LDR - Load Base + Offset" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```gas\n", "LDR R4, R1, VALUE ; R4 <- mem[R1 + VALUE]\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "15 - 12 | 11 - 9 | 8 - 6 | 5 - 0 |\n", "----| ------ | ----\n", "0110 | DR | BaseR | offset6\n", "\n", "
\n", "\n", "* DR <- mem[ BaseR + SEXT(offset6) ]\n", "* sets condition codes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.7.4 LEA - Load Effective Address" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```gas\n", "LEA R4, VALUE ; R4 <- address of VALUE\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "15 - 12 | 11 - 9 | 8 - 0 |\n", "----| ------ | ----\n", "1110 | DR | PCoffset9\n", "\n", "
\n", "\n", "* DR <- PC+ + SEXT(PCoffset9) \n", "* sets condition codes" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Example\n", "\n", "### Example of LD" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "Welcome to the LC-3 simulator.\n", "\n", "The contents of the LC-3 tools distribution, including sources, management\n", "tools, and data, are Copyright (c) 2003 Steven S. Lumetta.\n", "\n", "The LC-3 tools distribution is free software covered by the GNU General\n", "Public License, and you are welcome to modify it and/or distribute copies\n", "of it under certain conditions. The file COPYING (distributed with the\n", "tools) specifies those conditions. There is absolutely no warranty for\n", "the LC-3 tools distribution, as described in the file NO_WARRANTY (also\n", "distributed with the tools).\n", "\n", "Have fun.\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3000\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ "%reset" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: x2001\n", " x3001: xF025\n", " x3002: xF0F0\n", " x3003: x0000\n", " x3004: x0000\n", " x3005: x0000\n", " x3006: x0000\n", " x3007: x0000\n", " x3008: x0000\n", " x3009: x0000\n", " x300A: x0000\n", " x300B: x0000\n", " x300C: x0000\n", " x300D: x0000\n", " x300E: x0000\n", " x300F: x0000\n", " x3010: x0000\n", " x3011: x0000\n", " x3012: x0000\n", " x3013: x0000\n", " x3014: x0000\n", " x3015: x0000\n", " x3016: x0000\n", " x3017: x0000\n", " x3018: x0000\n", " x3019: x0000\n", " x301A: x0000\n", " x301B: x0000\n", " x301C: x0000\n", " x301D: x0000\n", " x301E: x0000\n", " x301F: x0000\n", " x3020: x0000\n", " x3021: x0000\n", " x3022: x0000\n", " x3023: x0000\n", " x3024: x0000\n", " x3025: x0000\n", " x3026: x0000\n", " x3027: x0000\n", " x3028: x0000\n", " x3029: x0000\n", " x302A: x0000\n", " x302B: x0000\n", " x302C: x0000\n", " x302D: x0000\n", " x302E: x0000\n", " x302F: x0000\n", " x3030: x0000\n", " x3031: x0000\n", " x3032: x0000\n", " x3033: x0000\n", " x3034: x0000\n", " x3035: x0000\n", " x3036: x0000\n", " x3037: x0000\n", " x3038: x0000\n", " x3039: x0000\n", " x303A: x0000\n", " x303B: x0000\n", " x303C: x0000\n", " x303D: x0000\n", " x303E: x0000\n", " x303F: x0000\n", " x3040: x0000\n", " x3041: x0000\n", " x3042: x0000\n", " x3043: x0000\n", " x3044: x0000\n", " x3045: x0000\n", " x3046: x0000\n", " x3047: x0000\n", " x3048: x0000\n", " x3049: x0000\n", " x304A: x0000\n", " x304B: x0000\n", " x304C: x0000\n", " x304D: x0000\n", " x304E: x0000\n", " x304F: x0000\n", " x3050: x0000\n", " x3051: x0000\n", " x3052: x0000\n", " x3053: x0000\n", " x3054: x0000\n", " x3055: x0000\n", " x3056: x0000\n", " x3057: x0000\n", " x3058: x0000\n", " x3059: x0000\n", " x305A: x0000\n", " x305B: x0000\n", " x305C: x0000\n", " x305D: x0000\n", " x305E: x0000\n", " x305F: x0000\n", " x3060: x0000\n", " x3061: x0000\n", " x3062: x0000\n", " x3063: x0000\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3003\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3000\n", "0010 000 000000001 ;; load next next into R0\n", "1111 0000 00100101 ;; HALT\n", "1111 0000 1111 0000\n", ".END" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 2\n", "Cycles: 19 (0.000010 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 1 Z: 0 P: 0 \n", "R0: xF0F0 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x3002 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example of LDI" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " xF0F0: xFEED\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: xF0F1\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG xF0F0\n", "1111 1110 1110 1101\n", ".END" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: xA001\n", " x3001: xF025\n", " x3002: xF0F0\n", " x3003: x0000\n", " x3004: x0000\n", " x3005: x0000\n", " x3006: x0000\n", " x3007: x0000\n", " x3008: x0000\n", " x3009: x0000\n", " x300A: x0000\n", " x300B: x0000\n", " x300C: x0000\n", " x300D: x0000\n", " x300E: x0000\n", " x300F: x0000\n", " x3010: x0000\n", " x3011: x0000\n", " x3012: x0000\n", " x3013: x0000\n", " x3014: x0000\n", " x3015: x0000\n", " x3016: x0000\n", " x3017: x0000\n", " x3018: x0000\n", " x3019: x0000\n", " x301A: x0000\n", " x301B: x0000\n", " x301C: x0000\n", " x301D: x0000\n", " x301E: x0000\n", " x301F: x0000\n", " x3020: x0000\n", " x3021: x0000\n", " x3022: x0000\n", " x3023: x0000\n", " x3024: x0000\n", " x3025: x0000\n", " x3026: x0000\n", " x3027: x0000\n", " x3028: x0000\n", " x3029: x0000\n", " x302A: x0000\n", " x302B: x0000\n", " x302C: x0000\n", " x302D: x0000\n", " x302E: x0000\n", " x302F: x0000\n", " x3030: x0000\n", " x3031: x0000\n", " x3032: x0000\n", " x3033: x0000\n", " x3034: x0000\n", " x3035: x0000\n", " x3036: x0000\n", " x3037: x0000\n", " x3038: x0000\n", " x3039: x0000\n", " x303A: x0000\n", " x303B: x0000\n", " x303C: x0000\n", " x303D: x0000\n", " x303E: x0000\n", " x303F: x0000\n", " x3040: x0000\n", " x3041: x0000\n", " x3042: x0000\n", " x3043: x0000\n", " x3044: x0000\n", " x3045: x0000\n", " x3046: x0000\n", " x3047: x0000\n", " x3048: x0000\n", " x3049: x0000\n", " x304A: x0000\n", " x304B: x0000\n", " x304C: x0000\n", " x304D: x0000\n", " x304E: x0000\n", " x304F: x0000\n", " x3050: x0000\n", " x3051: x0000\n", " x3052: x0000\n", " x3053: x0000\n", " x3054: x0000\n", " x3055: x0000\n", " x3056: x0000\n", " x3057: x0000\n", " x3058: x0000\n", " x3059: x0000\n", " x305A: x0000\n", " x305B: x0000\n", " x305C: x0000\n", " x305D: x0000\n", " x305E: x0000\n", " x305F: x0000\n", " x3060: x0000\n", " x3061: x0000\n", " x3062: x0000\n", " x3063: x0000\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3003\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3000\n", "1010 000 000000001 ;; R0 <- mem[mem[]]\n", "1111 0000 00100101 ;; HALT\n", "1111 0000 1111 0000\n", ".END" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 2\n", "Cycles: 21 (0.000010 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 1 Z: 0 P: 0 \n", "R0: xFEED R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x3002 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Example of LDR and LEA" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3000: xE002\n", " x3001: x6201\n", " x3002: xF025\n", " x3003: xF0F0\n", " x3004: x000F\n", " x3005: x0000\n", " x3006: x0000\n", " x3007: x0000\n", " x3008: x0000\n", " x3009: x0000\n", " x300A: x0000\n", " x300B: x0000\n", " x300C: x0000\n", " x300D: x0000\n", " x300E: x0000\n", " x300F: x0000\n", " x3010: x0000\n", " x3011: x0000\n", " x3012: x0000\n", " x3013: x0000\n", " x3014: x0000\n", " x3015: x0000\n", " x3016: x0000\n", " x3017: x0000\n", " x3018: x0000\n", " x3019: x0000\n", " x301A: x0000\n", " x301B: x0000\n", " x301C: x0000\n", " x301D: x0000\n", " x301E: x0000\n", " x301F: x0000\n", " x3020: x0000\n", " x3021: x0000\n", " x3022: x0000\n", " x3023: x0000\n", " x3024: x0000\n", " x3025: x0000\n", " x3026: x0000\n", " x3027: x0000\n", " x3028: x0000\n", " x3029: x0000\n", " x302A: x0000\n", " x302B: x0000\n", " x302C: x0000\n", " x302D: x0000\n", " x302E: x0000\n", " x302F: x0000\n", " x3030: x0000\n", " x3031: x0000\n", " x3032: x0000\n", " x3033: x0000\n", " x3034: x0000\n", " x3035: x0000\n", " x3036: x0000\n", " x3037: x0000\n", " x3038: x0000\n", " x3039: x0000\n", " x303A: x0000\n", " x303B: x0000\n", " x303C: x0000\n", " x303D: x0000\n", " x303E: x0000\n", " x303F: x0000\n", " x3040: x0000\n", " x3041: x0000\n", " x3042: x0000\n", " x3043: x0000\n", " x3044: x0000\n", " x3045: x0000\n", " x3046: x0000\n", " x3047: x0000\n", " x3048: x0000\n", " x3049: x0000\n", " x304A: x0000\n", " x304B: x0000\n", " x304C: x0000\n", " x304D: x0000\n", " x304E: x0000\n", " x304F: x0000\n", " x3050: x0000\n", " x3051: x0000\n", " x3052: x0000\n", " x3053: x0000\n", " x3054: x0000\n", " x3055: x0000\n", " x3056: x0000\n", " x3057: x0000\n", " x3058: x0000\n", " x3059: x0000\n", " x305A: x0000\n", " x305B: x0000\n", " x305C: x0000\n", " x305D: x0000\n", " x305E: x0000\n", " x305F: x0000\n", " x3060: x0000\n", " x3061: x0000\n", " x3062: x0000\n", " x3063: x0000\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x3005\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3000\n", "1110 000 000000010 ;; LEA R0 <- address of [PC+ + 2]\n", "0110 001 000 000001 ;; LDR R1 <- mem[r0 + 1]\n", "1111 0000 00100101 ;; HALT\n", "1111 0000 1111 0000\n", "0000 0000 0000 1111 \n", ".END" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Computation completed\n", "============================================================\n", "Instructions: 3\n", "Cycles: 24 (0.000012 milliseconds)\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x048E\n", "N: 0 Z: 0 P: 1 \n", "R0: x3003 R1: x000F R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x3003 \n" ] } ], "source": [ "%exe" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "============================================================\n", "Memory dump:\n", "============================================================\n", " x3100: x0001\n", " x3101: x0001\n", " x3102: x0001\n", " x3103: x0001\n", " x3104: x0001\n", " x3105: x0001\n", " x3106: x0001\n", " x3107: x0001\n", " x3108: x0001\n", " x3109: x0001\n", " x310A: x0000\n", " x310B: x0000\n", " x310C: x0000\n", " x310D: x0000\n", " x310E: x0000\n", " x310F: x0000\n", " x3110: x0000\n", " x3111: x0000\n", " x3112: x0000\n", " x3113: x0000\n", " x3114: x0000\n", " x3115: x0000\n", " x3116: x0000\n", " x3117: x0000\n", " x3118: x0000\n", " x3119: x0000\n", " x311A: x0000\n", " x311B: x0000\n", " x311C: x0000\n", " x311D: x0000\n", " x311E: x0000\n", " x311F: x0000\n", " x3120: x0000\n", " x3121: x0000\n", " x3122: x0000\n", " x3123: x0000\n", " x3124: x0000\n", " x3125: x0000\n", " x3126: x0000\n", " x3127: x0000\n", " x3128: x0000\n", " x3129: x0000\n", " x312A: x0000\n", " x312B: x0000\n", " x312C: x0000\n", " x312D: x0000\n", " x312E: x0000\n", " x312F: x0000\n", " x3130: x0000\n", " x3131: x0000\n", " x3132: x0000\n", " x3133: x0000\n", " x3134: x0000\n", " x3135: x0000\n", " x3136: x0000\n", " x3137: x0000\n", " x3138: x0000\n", " x3139: x0000\n", " x313A: x0000\n", " x313B: x0000\n", " x313C: x0000\n", " x313D: x0000\n", " x313E: x0000\n", " x313F: x0000\n", " x3140: x0000\n", " x3141: x0000\n", " x3142: x0000\n", " x3143: x0000\n", " x3144: x0000\n", " x3145: x0000\n", " x3146: x0000\n", " x3147: x0000\n", " x3148: x0000\n", " x3149: x0000\n", " x314A: x0000\n", " x314B: x0000\n", " x314C: x0000\n", " x314D: x0000\n", " x314E: x0000\n", " x314F: x0000\n", " x3150: x0000\n", " x3151: x0000\n", " x3152: x0000\n", " x3153: x0000\n", " x3154: x0000\n", " x3155: x0000\n", " x3156: x0000\n", " x3157: x0000\n", " x3158: x0000\n", " x3159: x0000\n", " x315A: x0000\n", " x315B: x0000\n", " x315C: x0000\n", " x315D: x0000\n", " x315E: x0000\n", " x315F: x0000\n", " x3160: x0000\n", " x3161: x0000\n", " x3162: x0000\n", " x3163: x0000\n", "\n", "============================================================\n", "Registers:\n", "============================================================\n", "PC: x310A\n", "N: 0 Z: 1 P: 0 \n", "R0: x0000 R1: x0000 R2: x0000 R3: x0000 \n", "R4: x0000 R5: x0000 R6: x0000 R7: x0000 \n" ] } ], "source": [ ".ORIG x3100\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", "0000 0000 0000 0001\n", ".END" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Calysto LC3", "language": "gas", "name": "calysto_lc3" }, "language_info": { "codemirror_mode": { "name": "gas", "version": 3 }, "file_extension": ".asm", "mimetype": "text/x-gas", "name": "gas" } }, "nbformat": 4, "nbformat_minor": 0 }